package com.soikc.kuaidiE.util;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;

import java.sql.ResultSet;
import java.sql.ResultSetMetaData;
import java.sql.SQLException;

public class ResultSetUtil {
    public static JSONObject toJsonObject(ResultSet resultSet){
        JSONObject jsonObject = new JSONObject();
        try {
            ResultSetMetaData metaData = resultSet.getMetaData();
            int columnCount = metaData.getColumnCount();
            for (int i=1;i<=columnCount;i++){
                String columnName = metaData.getColumnName(i);
                String value = resultSet.getString(i);
                jsonObject.put(columnName,value);
            }
        } catch (SQLException err) {
            err.printStackTrace();
        }
        return jsonObject;
    }
}
